import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
import { LoggerMiddleware } from '../logger/logger.middleware';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './entities/user.entity';
import { CacheModule } from '@nestjs/cache-manager';
import { RedisService } from '../redis/redis.service';
import { RedisModule } from '../redis/redis.module';
import { Role } from '../role/entities/role.entity';
import { RoleModule } from '../role/role.module';
import { Repository } from 'typeorm';
import { Permission } from '../permission/entities/permission.entity';
import { Article } from '../article/entities/article.entity';
import { Tag } from '../tag/entities/tag.entity';
import { Sort } from '../sort/entities/sort.entity';
import { Comment } from '../comment/entities/comment.entity';
import { Resource } from '../resource/entities/resource.entity';

@Module({
  // 需要导入才能有User表
  imports: [
    TypeOrmModule.forFeature([
      User,
      Role,
      Permission,
      Article,
      Tag,
      Sort,
      Comment,
      Resource,
    ]),
    RedisModule,
    CacheModule.register(),
  ],

  controllers: [UsersController],
  providers: [UsersService],
  exports: [UsersService],
})
export class UsersModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    // consumer.apply(LoggerMiddleware).forRoutes('users');
    // throw new Error('Method not implemented.');
  }
}
